/**
 * Copyright 2007-2010 非也
 * All rights reserved. 
 * 
 * This library is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License v3 as published by the Free Software
 * Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, see http://www.gnu.org/licenses/lgpl.html.
 *
 */
package org.fireflow2.designer.eclipse.commands.service.java;

import org.eclipse.jdt.core.IType;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.fireflow2.designer.eclipse.commands.service.AbstractServiceCreationWizard;
import org.fireflow2.designer.eclipse.modelwrapper.basic.ServiceDefWrapper;
import org.fireflow2.designer.eclipse.properties.IPropertyValidateListener;
import org.fireflow2.designer.eclipse.properties.service.java.JavaServiceEditPanel;

/**
 * 
 * @author 非也 nychen2000@163.com Fire Workflow 官方网站：www.firesoa.com 或者
 *         www.fireflow.org
 * 
 */
public class ConfigJavaServicePage extends WizardPage implements
		IPropertyValidateListener {
	private static final String TITLE = "Java调用配置";
	private static final String MESSAGE = "请输入Java全名或者Spring Bean Id；以及服务组件的中文名。";

	JavaServiceEditPanel editPanel = null;
	/**
	 * @param pageName
	 */
	protected ConfigJavaServicePage(String pageName) {
		super(pageName);
		this.setTitle(TITLE);
		this.setMessage(MESSAGE);
		this.setPageComplete(false);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
	 * .Composite)
	 */
	public void createControl(Composite parent) {
		AbstractServiceCreationWizard javaServiceCreationWizard = (AbstractServiceCreationWizard) this
				.getWizard();
		ServiceDefWrapper svcDef = (ServiceDefWrapper) javaServiceCreationWizard
				.getServiceDefWrapper();

		editPanel = new JavaServiceEditPanel(svcDef);
		editPanel.addServicePropertyModifyListener(this);
		Composite composite = new Composite(parent, SWT.NONE);
		this.setControl(editPanel.createControl(composite));
	}
	
	public IType getIType(){
		return editPanel.getIType();
	}
	

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.fireflow2.designer.eclipse.commands.service.
	 * IPropertyValidateListener#propertyModified()
	 */
	public void onValidateResult(boolean propertyIsOK,String errorMessage,String property,Object newValue,Object oldValue) {
		if (propertyIsOK){
			this.setMessage(MESSAGE);
			this.setErrorMessage(null);
			this.setPageComplete(true);
		}else{
			this.setPageComplete(false);
			this.setMessage(null);
			this.setErrorMessage(errorMessage);
		}
		
	}

}
